#region Using Statements

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Text;
using System.Web;
using System.Web.SessionState;

#endregion

namespace Dotss.Core
{

	/// <summary>
	/// A definition of what the StateServer client that the webserver will see
	/// </summary>
	public abstract class ClientProxy : SessionStateStoreProviderBase
	{

		#region Fields

		private static ServerLocator _ServerLocator;
		private static readonly object Sync = new object();

		#endregion

		/// <summary>
		/// Handle to a ServerLocator object that will determine where the client will store its session information
		/// </summary>
		public ServerLocator ServerLocator
		{
			get
			{
				
				if (_ServerLocator == null) SetLocator();
				
				return _ServerLocator;

			}	
			set { _ServerLocator = value; }
		}

		#region Methods

		/// <summary>
		/// Get the default serverlocator defined by the IoC container
		/// </summary>
		private static void SetLocator()
		{

			lock (Sync)
			{
				if (_ServerLocator == null)
				{
					_ServerLocator = Container.Instance.GetObject<ServerLocator>();
				}
			}

		}

		/// <summary>
		/// Internal method to allow a ServerLocator to be injected... useful for unit tests
		/// </summary>
		/// <param name="newLocator">Server locator to be used</param>
		internal static void SetLocator(ServerLocator newLocator)
		{

			lock (Sync)
			{
				_ServerLocator = newLocator;
			}

		}

		#endregion

		#region Properties

		protected ServerRO Server
		{
			get { return ServerLocator.GetServer(ClientConfig.Settings); }
		}

		#endregion

	}

}
